<!--suppress ALL -->
<div class="layui-fluid layui-anim website-anim" id="website-topic-annual" lay-title="评审管理"
     xmlns:th="http://www.w3.org/1999/xhtml">
    <div class="layui-row website-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body website-table-full">
                    <input type="hidden" id="topicClassifyCode" autocomplete="off" class="layui-input" data-th-value="${topicClassifyCode}"/>
                    <form class="layui-form layui-table-form" lay-filter="topic-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">选题名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="topicName" autocomplete="off" class="layui-input"
                                                   placeholder="请输入选题名称">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">期次</label>
                                        <div class="layui-input-inline" style="width: 60px;">
                                            <input type="text" name="year" id="year"  autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">状态</label>
                                        <div class="layui-input-inline">
                                            <select name="statusTypeCode">
                                                <option value="">请选择</option>
                                                <option
                                                        th:each="item : ${statusTypes}"
                                                        th:value="${item.code}" th:text="${item.name}">
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-blue-plain table-action"
                                     id="query">
                                    查询
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action"
                                     id="reset">
                                    重置
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action"
                                     id="exportReviewInfo">
                                    选题统计
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action"
                                     id="exportReviewExpert">
                                    专家名单
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="reviewAnnualTable" lay-data="{id: 'reviewAnnualTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<!--表格中字典的显示-->
<script type="text/html" id="subjectTypeAnnual">
    {{#
    var dictList=layui.dict.getByCodes(d.subjectTypeCodes);
    }}
    <span>
    {{# layui.each(dictList,function(index,item) { }}
    {{ item.name }}&nbsp;
    {{#  }); }}
    </span>
</script>
<script type="text/html" id="statusType">
    {{#
    var dict=layui.dict.getByCode(d.statusTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="researchType">
    {{#
    var dict=layui.dict.getByCode(d.researchTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="achievementFormType">
    {{#
    var dict=layui.dict.getByCode(d.achievementFormTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="statusTypeCode">
    {{#
    var dict=layui.dict.getByCode(d.statusTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="leaderCompany">
    {{#  if(d.leader){ }}
    <span>{{ d.leader.company }}</span>
    {{#  } }}
</script>
<script type="text/html" id="stage">
    {{# if( d.topicClassifyCode === 'entrust') { }}
    <span>{{d.stage}}</span>
    {{# } else { }}
    <span>{{d.year}}</span>
    {{# } }}
</script>

<!--表格中的操作栏-->
<script type="text/html" id="topic-option-annual">
    {{# if (d.planStatusCode === 'check') { }}
    <a lay-event="topic" class="website-green" shiro:hasPermission="review:assignExpert">学科分类</a>
    {{# } else if(d.statusTypeCode === 'subject' && d.planStatusCode === 'subject') { }}
    <a lay-event="expert" class="website-green" shiro:hasPermission="review:assignExpert">专家分配</a>
    {{# } else { } }}
    <a lay-event="showExpert" class="website-green" shiro:hasPermission="review:assignExpert">查看专家</a>
</script>

<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'form', 'table', 'website', 'dict','laydate'], function () {
        var $ = layui.jquery,
                website = layui.website,
                form = layui.form,
                table = layui.table,
                dict = layui.dict,
                laydate = layui.laydate,
                dropdown = layui.dropdown,
            $view = $('#website-topic-annual'),
            $query = $view.find('#query'),
            $exportReviewInfo = $view.find('#exportReviewInfo'),
            $exportReviewExpert = $view.find('#exportReviewExpert'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
                sortObject = {field: 'createTime', type: null},
                tableIns,
                createTimeFrom,
                createTimeTo;
        form.render();

        //初始化年份的搜索框
        laydate.render({
            elem: '#year', //指定元素
            type: 'year',
            trigger: 'click',
            value: new Date()
        });
        initTable();

        /**
         * 搜索按钮旁边的更多，这个是下拉控件
         **/


        /**
         * table操作栏的按钮监听事件
         **/
        table.on('tool(reviewAnnualTable)', function (obj) {
            debugger
            var data = obj.data, layEvent = obj.event;
            if (layEvent === 'expert') {
                website.navigate("/biz/review/" + data.topicId + "/assign/" + data.topicClassifyCode);
            }
            if (layEvent === 'showExpert') {
                website.navigate("/biz/review/" + data.topicId + "/showExpert/" + data.topicClassifyCode);
            }
            if (layEvent === 'topic') {
                website.navigate("/biz/review/"+ data.topicId + "/modifySubject/" + data.topicClassifyCode);
            }
            // if (layEvent === 'topic') {
            //     website.modal.open('学科分类', 'biz/review/'+ data.topicId + '/modifySubject/' + data.topicClassifyCode, {
            //         area: $(window).width() <= 750 ? '95%' : '50%',
            //         success: function(layero, index){
            //             var body = layero.find('#website-choose');
            //             body.find("input[name=fatherId]").val("website-topic-annual");
            //         }
            //     });
            // }
        });

        /**
         * 表格的排序点击
         **/
        table.on('sort(reviewAnnualTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

            $query.on('click', function () {
        var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
        tableIns.reload({where: params, page: {curr: 1}});
        });

            $exportReviewInfo.on('click', function () {
        var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
        if (!params.year) {
        website.alert.warn('请选择需导出数据的期次');
        return;
        }
        website.download(ctx + 'review/'+ $("#topicClassifyCode").val() + '/topicReviewInfo', params, '中国法学会' + params.year + '各选题申报情况及拟邀请评审专家学科.doc');
        });

        $exportReviewExpert.on('click', function () {
    var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
    if (!params.year) {
    website.alert.warn('请选择需导出数据的期次');
    return;
    }
    website.download(ctx + 'review/'+ $("#topicClassifyCode").val() + '/exportReviewExpertName', params, '中国法学会' + params.year + '年度部级法学研究评审专家名单表.doc');
        });

            $reset.on('click', function () {
            $searchForm[0].reset();
        sortObject.type = 'null';
        createTimeTo = null;
        createTimeFrom = null;
        tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });

        /**
         * 初始化表格
         */
        function initTable() {
            tableIns = website.table.init({
                elem: $view.find('table'),
                id: 'reviewAnnualTable',
                url: ctx + 'review/'+ $("#topicClassifyCode").val() + '/list',
                where: {year: new Date().getFullYear() , planNo: '001'},
                cols: [[
                    /*{type: 'checkbox'},*/
                    { type: 'numbers', title: '序号'},
                    { title: '期次', templet: '#stage', width: 80},
                    {field: 'topicCode', title: '指南序号', width: 100},
                    {field: 'topicName', title: '选题名称', minWidth: 150},
                    {field: 'statusTypeCode', title: '状态', templet: '#statusType', width: 140},
                    {field: 'subjectTypeCodes', title: '学科分类', templet: '#subjectTypeAnnual', width: 100},
                    // {field: 'expertNames', title: '评审专家', minWidth: 100},
                    {title: '操作', toolbar: '#topic-option-annual', width: 180}
                ]]
            });
        }

        /**
         * 获取查询条件
         * @returns {{}}
         */
        function getQueryParams() {
            var params = $searchForm.serializeJson();
            return params;
        }

    })
</script>